class Encrypter


#@public_key_file = 'public.pem';  
@private_key_file = 'private.pem';  
@password = 'robculo8'

require 'openssl'  
require 'base64'  
  
#string = 'Hello World!';  
  
  def encrypt(string)
  
  puts "\n--string:\n#{string}\n\n"
  
    #public_key =  OpenSSL::PKey::RSA.new(File.read(@public_key_file))  
    
    #since I cannot read the public.pem public key file (where should I put that file?)
    #I write here the key:
    public_key_conts = "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4GCRUTY46qoiOTeaDjo3
vTSg0f8s3hX3n/8EvdIGcFe60D5m+sE9zQO3vXxy2cZEAMEwhiSp+XDoSzWRHE7L
VG1bqMEcrgr9zYYm4WqGvT0ltIWYC8d5b53GbB92RoqKFocPjag21HjEiKsU6rxo
uz9l7QbaiqN6F8EetoFkLzo2qUVrjtmYiUpLNDD2BzXXvkpz8RbcQ5P5TeX8HAJS
mNB72gEXH5FW9ci3oN9NW++dWv4rRS/L7cgaGrbDNPGtwct/pBl2J/qS3hYBThqu
DE+UzCfEMrEkHy1vggJItkPI9P9WOL1fhVaUflRPDARRM3NqQh4vITKpS44ApeYM
6wIDAQAB
-----END PUBLIC KEY-----"
    public_key = OpenSSL::PKey::RSA.new(public_key_conts)
    
    encrypted_string = Base64.encode64(public_key.public_encrypt(string))  
    
    return encrypted_string#, "n"  
  end
  
  
  
  def decrypt(string)
    
    private_key = OpenSSL::PKey::RSA.new(File.read(@private_key_file),password)  
    string = private_key.private_decrypt(Base64.decode64(encrypted_string))  
  
    return  string#, "n"  
    
  end
  
  
end